<template>
    <div id="management" class="mt-3">
        <div class="row">
            <div class="col-sm-12 col-md-8">
                <Add></Add>
            </div>
            <div class="col-sm-12 col-md-4">
                <h3 class="text-muted my-5">菜单</h3>
                <table class="table table-default">
                    <thead>
                        <tr>
                            <th>品种</th>
                            <th>删除</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="item in getMenus">
                            <td>{{item.name}}</td>
                            <td>
                                <button class="btn btn-outline-danger btn-sm" @click="onDelete(item.objectId)">&times;</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</template>

<script>
    import Add from './Add'

    export default {
        name: "Management",
        components: {
            Add
        },
        data() {
            return {
            }
        },
        methods: {
            // setMenus() {
            //     const query = Bmob.Query("Pizza");
            //     query.order("-createdAt");
            //     query.find().then(response => this.$store.commit("setMenus", response)).catch(error => console.log(error));
            //     console.log("setMenus");
            // },
            onDelete(id) {
                const query = Bmob.Query("Pizza");
                query.destroy(id).then(response => this.$store.commit("setMenus")).catch(error => console.log(error))
            }
        },
        computed: {
            getMenus() {
                return this.$store.getters.getMenus;
            }
        },
        created() {
            this.$store.commit("setMenus");
        }
    }
</script>

<style scoped>
    /**/
</style>